import Vue from 'vue';
import VueRouter from 'vue-router';

import Index from '@/views/index/index.vue';
import Login from '@/views/login';
import SystemManage from '@/views/systemManage/systemManage';

import store from '@/store/index.js';

Vue.use(VueRouter);


const routes = [
  { path: '/', component: Index,
    children: [
      { path: '/system-manage', component: SystemManage , name : "/system-manage"},
      
      
      
    ]
  },
  { path: '/login', component: Login, name: "login" },
  

];

const router =  new VueRouter({
  mode: 'hash',
  routes,
});


router.beforeEach((to, from , next) => {
  let path = to.path;
  if (path === '/login') {
    next();
  }
  
  if (store.state.token) {
    next();
  } else {
    router.push({ path: '/login' });
    next();
  }


});

export default router;